'use strict';
const dayjs = require("dayjs");
module.exports = app => {
  const { STRING, INTEGER, TINYINT } = app.Sequelize;
    const Model = app.model.define(
      'staffWorkLog',
      {
          id: {type: INTEGER, primaryKey: true, autoIncrement: true},
          /**
           * 考勤表
           */
            staff_id: INTEGER,
            company: INTEGER,
            work_type: TINYINT(1), // 1: 上班  2: 下班  3: 请假
            // 延迟 上班迟到 下班早退
            delay: TINYINT(1),
            start_time: {
                type: app.Sequelize.DATE,
                get() {
                    return dayjs(this.getDataValue('start_time')).format('YYYY-MM-DD HH:mm:ss');
                }
            },
            end_time: {
                type: app.Sequelize.DATE,
                get() {
                    return dayjs(this.getDataValue('end_time')).format('YYYY-MM-DD HH:mm:ss');
                }
            },
            created_time: {
                type: app.Sequelize.DATE,
                allowNull: false,
                get() {
                    return dayjs(this.getDataValue('created_time')).format('YYYY-MM-DD HH:mm:ss');
                }
           },
           updated_time: {
              type: app.Sequelize.DATE,
              allowNull: false,
              get() {
                  return dayjs(this.getDataValue('updated_time')).format('YYYY-MM-DD HH:mm:ss');
              }
           },
      },
      {
          tableName: 'staff_work_log',
          timestamps: true, // 启用时间戳(createdAt, updatedAt)
          updatedAt: 'updated_time', // 不想要 updatedAt
          createdAt: 'created_time', // 想要  createdAt 但是希望名称叫做 created_at
      }
    );
    Model.associate = function() {
    }
    return Model
};
